#region Copyright 2006 - Evolution Tecnologia Ltda.
//
// Author: Rafael Franco Carvalho (rafael@Evolutiontec.com.br)
//
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: Groups.cs
#endregion


using System;
using System.Collections.Generic;
using System.Text;

namespace csharp.rad.general
{
    public class Groups
    {
        private List<Group> groupsItems = new List<Group>();
        private Database myDatabase;

        public List<Group> Items
        {
            get
            {
                return groupsItems;
            }
            set
            {
                groupsItems = value;
            }
        }

        public Groups(Database myDatabase)
        {
            this.myDatabase = myDatabase;
        }

        public void GetData()
        {
            String commandText;
            String tableName = "groups";
            Database.Result databaseResult = new Database.Result();
            System.Data.DataSet sqlDataSet = new System.Data.DataSet();

            groupsItems.Clear();
            commandText = "SELECT group_id "
                        + "FROM groups "
                        + "ORDER BY group_name";
            sqlDataSet = myDatabase.ExecuteQuery(commandText, tableName, out databaseResult);
            foreach (System.Data.DataRow dataRecord in sqlDataSet.Tables[tableName].Rows)
            {
                Group groupItem = new Group(myDatabase);
                groupItem.GetData(System.Convert.ToString(dataRecord["group_id"]));
                groupsItems.Add(groupItem);
            }
            sqlDataSet.Dispose();
        }
    }
}
